package com.jm.offer.easy;

import java.util.HashMap;

/**
 * @Description https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/
 * @date 2022/4/22 14:44
 */
public class _50第一个只出现一次的字符 {

    public static void main(String[] args) {
        System.out.println(firstUniqChar("aadadaad"));
    }

    public static char firstUniqChar(String s) {
        char[] chars = s.toCharArray();
        HashMap<Character,Boolean> map = new HashMap<>();
        for (char c : chars) {
            // 如果 k 已经存在用 false 覆盖 ture
            map.put(c,!map.containsKey(c));
        }
        for (char c : chars) {
            if (map.get(c)){
                return c;
            }
        }
        return ' ';
    }
}
